package com.chuanwei.service.Impl;

import com.chuanwei.mapper.DeptMapper;
import com.chuanwei.pojo.Dept;
import com.chuanwei.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public void deletById(Integer id) {
        deptMapper.deletById(id);
    }

    @Override
    public void add(Dept dept) {
        //1.前端只是传来了jason格式的数据，但是还是要补全基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //调用Mapper层方法，插入数据
        deptMapper.add(dept);
    }


    @Override
    public Dept getById(Integer id) {
       return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {

        //补全基础属性
        dept.setUpdateTime(LocalDateTime.now());

        //更新数据
        deptMapper.update(dept);
    }
}
